package com.shop.controller;

/**
 * 管理员
 * @author 沙捞雕像
 */

import com.shop.pojo.User;
import com.shop.service.AdminService;
import com.shop.service.AdminServiceImpl;
import com.shop.util.MD5Utils;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/admin")
public class AdminController extends BaseServlet{
    public String login(HttpServletRequest request, HttpServletResponse response) {
//        获取用户参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
//        判断用户名密码是否为空，如果为空重新跳转到登录页面
        if(username == null || password == null){
            return  "redirct："+request.getContextPath()+"/admin/login.jsp";
        }
        //调用service 校验用户名和密码
        AdminService adminService = new AdminServiceImpl();
        User user = adminService.login(username, password);
        //如果非空将得到的用户放进session（一直携带）来传给前端页面
        if(user!=null){
            request.getSession().setAttribute("admin",user);
            return "redirect:"+request.getContextPath()+"/admin/admin.jsp";
        }else {
            return "redirect:"+request.getContextPath()+"/admin/admin.jsp";
        }
//        管理员登录
//       request.setAttribute("admin", "aad");
//        //TODO 对应的login.jsp中为何不会跳转。

    }

}
